package summerprojectFX.view;

import summerprojectFX.controller.MenuController;
import javafx.scene.control.CheckMenuItemBuilder;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.MenuItemBuilder;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.stage.Stage;

public class MainMenu {

	public MenuBar createMenu(Stage primaryStage, MainView view) {

		MenuBar menuBar = new MenuBar();
		Menu viewMenu = new Menu("View");
                Menu helpMenu = new Menu("Help");
                
                MenuItem helpContent = MenuItemBuilder.create().text("Help Contents").onAction(new MenuController(primaryStage, view)).build();
                helpMenu.getItems().add(helpContent);

		MenuItem fscreen = MenuItemBuilder
				.create()
				.text("Full Screen")
				.accelerator(
						new KeyCodeCombination(KeyCode.F,
								KeyCombination.CONTROL_DOWN))
				.onAction(new MenuController(primaryStage, view)).build();
		viewMenu.getItems().add(fscreen);

		Menu edit = new Menu("Edit");
		MenuItem num = MenuItemBuilder
				.create()
				.text("Number System")
				.accelerator(
						new KeyCodeCombination(KeyCode.N,
								KeyCombination.CONTROL_DOWN))
				.onAction(new MenuController(primaryStage, view)).build();
		edit.getItems().add(num);

		MenuItem transpose = MenuItemBuilder
				.create()
				.text("Transpose")
				.accelerator(
						new KeyCodeCombination(KeyCode.T,
								KeyCombination.CONTROL_DOWN))
				.onAction(new MenuController(primaryStage, view)).build();
		edit.getItems().add(transpose);

		MenuItem previous = MenuItemBuilder
				.create()
				.text("Previous")
				.accelerator(
						new KeyCodeCombination(KeyCode.P,
								KeyCombination.CONTROL_DOWN))
				.onAction(new MenuController(primaryStage, view)).build();
		edit.getItems().add(previous);

		MenuItem original = MenuItemBuilder
				.create()
				.text("Restore Original")
				.accelerator(
						new KeyCodeCombination(KeyCode.R,
								KeyCombination.CONTROL_DOWN))
				.onAction(new MenuController(primaryStage, view)).build();
		edit.getItems().add(original);
		
		

		Menu menu = new Menu("File");
		MenuItem open = MenuItemBuilder
				.create()
				.text("Open File")
				.accelerator(
						new KeyCodeCombination(KeyCode.O,
								KeyCombination.CONTROL_DOWN))
				.onAction(new MenuController(primaryStage, view)).build();
		menu.getItems().add(open);

		MenuItem close = MenuItemBuilder
				.create()
				.text("Close")
				.accelerator(
						new KeyCodeCombination(KeyCode.W,
								KeyCombination.CONTROL_DOWN))
				.onAction(new MenuController(primaryStage, view)).build();
		menu.getItems().add(close);

		MenuItem closeall = MenuItemBuilder
				.create()
				.text("Close All")
				.accelerator(
						new KeyCodeCombination(KeyCode.W,
								KeyCombination.SHIFT_DOWN,
								KeyCombination.CONTROL_DOWN))
				.onAction(new MenuController(primaryStage, view)).build();
		menu.getItems().add(closeall);

		menu.getItems().add(new SeparatorMenuItem());


		MenuItem saveall = MenuItemBuilder
				.create()
				.text("Save As")
				.accelerator(
						new KeyCodeCombination(KeyCode.S,
								KeyCombination.SHIFT_DOWN,
								KeyCombination.CONTROL_DOWN))
				.onAction(new MenuController(primaryStage, view)).build();
		menu.getItems().add(saveall);
		

		MenuItem pdf = MenuItemBuilder
				.create()
				.text("Export As PDF")
				.accelerator(
						new KeyCodeCombination(KeyCode.P,
								KeyCombination.CONTROL_DOWN))
				.onAction(new MenuController(primaryStage, view)).build();
		menu.getItems().add(pdf);
               

		menu.getItems().add(new SeparatorMenuItem());

		MenuItem exit = MenuItemBuilder
				.create()
				.text("Exit")
				.accelerator(
						new KeyCodeCombination(KeyCode.Q,
								KeyCombination.CONTROL_DOWN))
				.onAction(new MenuController(primaryStage, view)).build();

		menu.getItems().add(exit);

		menuBar.getMenus().addAll(menu, edit, viewMenu, helpMenu);
		// Makes it so the menu binds to the window width.
		menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

		return menuBar;
	}
}
